package org.cskj.demo.controller;

import org.cskj.demo.pojo.User;
import org.cskj.demo.service.imp.UserService;
import org.cskj.demo.util.UpPhotoNameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Controller
@ResponseBody
@RequestMapping("/testupload")
public class Imgcontroller {
    @Autowired
    private UserService userService;
    @RequestMapping("/upload")
    public String upload(@RequestParam("file") MultipartFile file,HttpServletRequest request){
        String url = userService.upload(file, request);
        return url;
    }

    @RequestMapping("/zhengshi")
    public String tijiao(User user,String url,HttpServletRequest request){
        System.out.println(user);
        User user1 = userService.selectBykey(user.getUsid());
        user1.setUsimg(url);
        user1.setUspass(user.getUspass());
        userService.update(user1);
        return "okk";
    }
}
